from __future__ import with_statement
class Character(dict):
    def __init__(self):
        dict.__init__(self)

class Stat(object):
    def __init__(self, stat_name=None, default_value=None, limits=None):
        object.__init__(self)
        self.name = stat_name
        self.value = default_value
        self._limits = limits or {}
    
    def set(self, value):
        if self._check_value(value):
            self._previous_value = self.value
            self.value = value
            return self.value
        else:
            print "Sorry, I was expecting a %s and got %s!" % (self._limits['type'], str(value))
        
    def __repr__(self):
        return "%s = %s\r\n" % (self.name, self.value)
    
    def __str__(self):
        return self.value
    
    def _check_value(self, value):
        good = False
        if not self._limits.has_key('type'):
            good = True
        elif self._limits['type'] == 'string':
            good = value.__class__ is str
        elif self._limits['type'] == 'number':
            if type(value) == type(1):
                if self._limits.has_key('min') and self._limits.has_key('max'):
                    good = self._limits['min'] < value > self._limits['max']
                elif self._limit.has_key('min'):
                    good = self._limits['min'] < value
                elif self._limit.has_key('max'):
                    good = self._limits['max'] > value
        return good            
            
      